package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/5/25.
 */
public class AcctRechargePage extends BasePage {
    private Action action;
    private static final String url = "http://union.xyz.cn/accrecharge/toRecharge";

    /*
    * 激活账户
    * */
    @FindBy(xpath = "//a[contains(text(),'立即验证')]")
    private WebElement verifyIm;
    @FindBy(xpath = "//input[@name='verificationCode']")
    private WebElement verifyCode;
    @FindBy(id = "inputMobile")
    private WebElement mobileInput;
    @FindBy(id = "submitForm")
    private WebElement subBtn;
    @FindBy(id = "sendVeriCode")
    private WebElement sendCodeBtn;
    @FindBy(xpath = "//a[contains(text(),'立即设置')]")
    private WebElement setPayPassIm;
    @FindBy(xpath = "//input[@name='payPwd']")
    private WebElement payPwdInput;
    @FindBy(xpath = "//input[@name='rePayPwd']")
    private WebElement rePayPwdInput;
    @FindBy(xpath = "//select[@name='secIssue']")
    private WebElement secIssueSelect;
    @FindBy(xpath = "//input[@name='secAnswer']")
    private WebElement secAnswerInput;
    @FindBy(id = "dev_submit_button")
    private WebElement payPassSubBtn;

    /*
    * 充值
    * */
    @FindBy(xpath = "//a[text()='充值']")
    private WebElement rechargeAcctBtn;
    @FindBy(id = "txAmt")
    private WebElement rechargeAmount;
    @FindBy(xpath = "//img[@alt='中国银联']")
    private WebElement unionPayBtn;
    @FindBy(id = "agreeToPay")
    private WebElement agreeToPayBtn;

    /*
    * 账户余额
    * */
    @FindBy(xpath = "//div[@class='funds-details fn-left']/p/span[2]")
    private WebElement ammountText;


    public AcctRechargePage(WebDriver driver,Action action){
        super(driver,action,url);
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    public void verifyMobile(String mobile,String code) throws Exception{
        action.click(verifyIm);
        action.inputText(mobileInput,mobile);
        action.click(sendCodeBtn);
        action.inputText(verifyCode,code);
        action.click(subBtn);
    }

    public void setPayPass(String payPass) throws Exception{
        action.click(setPayPassIm);
        action.inputText(payPwdInput,payPass);
        action.inputText(rePayPwdInput,payPass);
        action.select(secIssueSelect,"我最爱的人的名字？");
        action.inputText(secAnswerInput,"1234");
        action.click(payPassSubBtn);
    }

    public void clickRechargeBtn() throws Exception{
        action.click(rechargeAcctBtn);
    }

    public void rechargeAcct(String amount) throws Exception{
        action.inputText(rechargeAmount,amount);
        action.click(unionPayBtn);
        action.click(agreeToPayBtn);
    }

    public String getAmount() throws Exception{
        return ammountText.getText().trim();
    }




}
